#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[])
{
	int num;
	int cnt=0,ans=0,pre;
	int arr[35]={0};
	cin>>num;
	if(num==1){
		arr[cnt]=1;
	}else if(num==2){
		arr[cnt]=2;
	}
	pre=num;
	cnt++;
	while(cin>>num){
		if(num==1){
			arr[cnt]=1;
		}else if(num==2&&pre==1){
			arr[cnt]=2;
		}else if(num==2&&pre==2){
			arr[cnt]=arr[cnt-1]+2;
		}else{
			break;
		}
		pre=num;
		cnt++;
	}
	for (int i = 0; i < 35; ++i)
	{
		ans+=arr[i];
	}
	printf("%d\n", ans);
	return 0;
}